package github.fafaovo.common.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import github.fafaovo.example;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.entity.player.ServerPlayerEntity;

public class BackPostionCommand {
    public BackPostionCommand(CommandDispatcher<CommandSource> dispatcher)
    {
        dispatcher.register(Commands.literal("example").then(Commands.literal("back").executes(
                (c)->{
                    return backPos(c.getSource());
                }
        )));
    }
    private int backPos(CommandSource source) throws CommandSyntaxException
    {
        ServerPlayerEntity player = source.asPlayer();
        if(player.getPersistentData().getIntArray(example.MOD_ID + ".save_pos").length != 0)
        {
            int[] playerPos = player.getPersistentData().getIntArray(example.MOD_ID  + ".save_pos");
            player.setPositionAndUpdate(playerPos[0],playerPos[1],playerPos[2]);
            return 1;
        }
        else
        {
            return -1;
        }

    }
}
